home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / SOURCES / WCURSOR.C < prev    next >
C/C++ Source or Header  |  1992-02-25  |  2KB  |  105 lines

  1.  /*
  2.  *  MS Windows - dependent cursors
  3.  */
  4.  
  5. #include <Interviews\bitmap.h>
  6. #include <Interviews\color.h>
  7. #include <Interviews\cursor.h>
  8. #include <Interviews\font.h>
  9. #include <Interviews\X11\worldrep.h>
  10. #include <mem.h>
  11.  
  12.  
  13. void MakeWinFormat (
  14.     int* pat, int* mask, unsigned* andmask, unsigned* xormask, boolean bitmapbits
  15. ) {
  16.     memset(andmask, 0xff, 128);
  17.     memset(xormask, '\0', 128);
  18.     for (int j = 0, i = 0; i < 16; i++, j += 2) {
  19.     andmask[j] = ~mask[i];
  20.     xormask[j] = mask[i] & pat[i];
  21.  
  22.     }
  23.  
  24.     if (!bitmapbits) {
  25.     BYTE highbyte;
  26.  
  27.     for (i = 0; i < 32; i += 2) {
  28.         highbyte = HIBYTE(andmask[i]);
  29.         andmask[i] <<= 8;
  30.         andmask[i] += highbyte;
  31.  
  32.         highbyte = HIBYTE(xormask[i]);
  33.         xormask[i] <<= 8;
  34.         xormask[i] += highbyte;
  35.     }
  36.     } else {
  37.     for (i = 0; i < 32; i += 2) {
  38.         xormask[i] = ~(xormask[i] | andmask[i]);
  39.     }
  40.     }
  41. }
  42.  
  43. Cursor::Cursor (Bitmap* p, Bitmap* m, Color* fg, Color* bg) {
  44.     int bitmap_pattern[16];
  45.     int bitmap_mask[16];
  46.     unsigned andmask[64];
  47.     unsigned xormask[64];
  48.  
  49.     GetBitmapBits((HBITMAP)p->Map(), 32, (LPSTR)bitmap_pattern);
  50.     GetBitmapBits((HBITMAP)m->Map(), 32, (LPSTR)bitmap_mask);
  51.  
  52.     x = -p->Left();
  53.     y = p->Height() -1 -(-p->Bottom());
  54.     foreground = fg;
  55.     background = bg;
  56.  
  57.     MakeWinFormat(
  58.     bitmap_pattern, bitmap_mask, andmask, xormask, true
  59.     );
  60.  
  61.     id = (void*)CreateCursor(
  62.             _world->hinstance(), x, y, 32, 32,
  63.             (LPSTR)andmask, (LPSTR)xormask
  64.         );
  65.     is_stock_cursor = false;
  66. }
  67.  
  68. Cursor::Cursor (Font* font, int pattern, int mask, Color* fg, Color* bg) {
  69.     Bitmap* p = new Bitmap(font, pattern);
  70.     Bitmap* m = new Bitmap(font, mask);
  71.  
  72.     Cursor(p, m, fg, bg);
  73.  
  74.     delete p;
  75.     delete m;
  76.     is_stock_cursor = false;
  77. }
  78.  
  79. Cursor::Cursor (long int c, Color* fg, Color* bg) {
  80.     id = (void*)LoadCursor(NULL, MAKEINTRESOURCE(c));
  81.     is_stock_cursor = true;
  82. }
  83.  
  84. void* Cursor::Id () {
  85.     if (id == nil && pat != nil && mask != nil) {
  86.     unsigned andmask[64];
  87.     unsigned xormask[64];
  88.  
  89.     MakeWinFormat(pat, mask, andmask, xormask, false);
  90.     id = (void*)CreateCursor(
  91.             _world->hinstance(), x, y, 32, 32,
  92.             (LPSTR)andmask, (LPSTR)xormask
  93.             );
  94.         is_stock_cursor = false;
  95.     }
  96.     return id;
  97. }
  98.  
  99. Cursor::~Cursor () {
  100.     if (id != nil && !is_stock_cursor) {
  101.     DestroyCursor((HCURSOR)id);
  102.     }
  103. }
  104.  
  105.